//
//  SexSelectionViewController.m
//  safeLady
//
//  Created by Justsoso on 2017/6/16.
//  Copyright © 2017年 xmy. All rights reserved.
//

#import "SexSelectionViewController.h"
#import "PreLoginViewModel.h"

@interface SexSelectionViewController ()
@property (weak, nonatomic) IBOutlet UILabel *titleLabel;
@property (weak, nonatomic) IBOutlet UIButton *manButton;
@property (weak, nonatomic) IBOutlet UIButton *womanButton;
@property (weak, nonatomic) IBOutlet UIButton *nextButton;

@property (nonatomic, assign) BOOL isChoose_man;
@property (nonatomic, assign) BOOL isChoose_woman;

@property (nonatomic, strong) NSString *sex;

@property (nonatomic, strong) NSMutableDictionary *info;

@property (nonatomic,strong) PreLoginViewModel *viewModel;


@end

@implementation SexSelectionViewController
@synthesize viewModel = _viewModel;

- (NSMutableDictionary *)info {
    if (!_info) {
        _info = [NSMutableDictionary dictionary];
    }
    return _info;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self.navigationController.navigationBar setHidden:YES];
    
    [self.manButton setImage:[UIImage imageNamed:@"man"] forState:UIControlStateNormal];
    self.manButton.adjustsImageWhenHighlighted = NO;
    
    [self.womanButton setImage:[UIImage imageNamed:@"woman"] forState:UIControlStateNormal];
    self.womanButton.adjustsImageWhenHighlighted = NO;
    
    [self.nextButton setTitle:@"下一步" forState:UIControlStateNormal];
    [self.nextButton setBackgroundColor:[UIColor lightGrayColor]];
    [self.nextButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    self.nextButton.layer.cornerRadius = 5.0;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (IBAction)chooseMan:(id)sender {
    if (self.isChoose_woman) {
        [self.womanButton setImage:[UIImage imageNamed:@"woman"] forState:UIControlStateNormal];
        self.isChoose_woman = NO;
    }
    [self.manButton setImage:[UIImage imageNamed:@"man_Highigted"] forState:UIControlStateNormal];
    self.isChoose_man = YES;
    self.sex = @"1";
    
    
}
- (IBAction)chooseWoman:(id)sender {
    if (self.isChoose_man) {
        [self.manButton setImage:[UIImage imageNamed:@"man"] forState:UIControlStateNormal];
        self.isChoose_man = NO;
    }
    [self.womanButton setImage:[UIImage imageNamed:@"woman_Highigted"] forState:UIControlStateNormal];
    self.isChoose_woman = YES;
    self.sex = @"2";
    
    
}
- (IBAction)nextButton:(id)sender {
    
    if (!self.sex) {
        [self hiddenHUDWithString:@"请选择性别" error:nil];
    }else {
//        [NSUserDefaults standardUserDefaults] setObject:[UserClient sharedUserClient].userInfo[@"sex"] forKey:@""
        self.info = [[[NSUserDefaults standardUserDefaults] objectForKey:@"userInfo"] mutableCopy];
//        [self.info setValue:self.sex forKey:@"sex"];
        [self.info setValue:self.sex forKeyPath:@"sex"];
//        [self.info removeObjectForKey:@"sex"];
        [[NSUserDefaults standardUserDefaults] setObject:self.info forKey:@"userInfo"];
        [[NSUserDefaults standardUserDefaults] synchronize];
        /* 请求更新用户信息接口 */
        HttpManagerCenter* httpCenter = [HttpManagerCenter sharedHttpManager];
        [[httpCenter setSex:self.sex resultClass:nil] subscribeNext:^(BaseModel *model) {
            if (model.code == 200) {
                /* 进入首页 */
                [SharedAppDelegate openAppMainVCT];
            }
        }];
    }
    
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
